package cn.com.lms.business.log.persistence.entity;

import com.bnzj.core.json.DateDeserializer;
import com.bnzj.core.util.FbConstant;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "bnz_sys_user_action_log")
public class UserActionLog  implements Serializable {
    private Integer id;
    private String actorName;
    private String actionDescr;
    private Short actionType;
    private String actionResult;
    private Date actionAt;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "actor_name")
    @Schema(description = "操作人")
    public String getActorName() {
        return actorName;
    }

    public void setActorName(String actorName) {
        this.actorName = actorName;
    }

    @Basic
    @Column(name = "action_descr")
    @Schema(description = "操作描述")
    public String getActionDescr() {
        return actionDescr;
    }

    public void setActionDescr(String actionDescr) {
        this.actionDescr = actionDescr;
    }

    @Basic
    @Column(name = "action_type")
    @Schema(description = "操作类型 登录、查询、修改、新增、删除 ")
    public Short getActionType() {
        return actionType;
    }

    public void setActionType(Short actionType) {
        this.actionType = actionType;
    }

    @Basic
    @Column(name = "action_result")
    @Schema(description = "操作结果（成功/失败）")
    public String getActionResult() {
        return actionResult;
    }

    public void setActionResult(String actionResult) {
        this.actionResult = actionResult;
    }

    @Basic
    @Column(name = "action_at")
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = FbConstant.DATETIME_FORMAT)
    @JsonDeserialize(using = DateDeserializer.class)
    @JsonFormat(pattern = FbConstant.DATETIME_FORMAT, timezone = "GMT+8")
    @Schema(description = "操作时间")
    public Date getActionAt() {
        return actionAt;
    }

    public void setActionAt(Timestamp actionAt) {
        this.actionAt = actionAt;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserActionLog that = (UserActionLog) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(actorName, that.actorName) &&
                Objects.equals(actionDescr, that.actionDescr) &&
                Objects.equals(actionType, that.actionType) &&
                Objects.equals(actionResult, that.actionResult) &&
                Objects.equals(actionAt, that.actionAt);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, actorName, actionDescr, actionType, actionResult, actionAt);
    }


    public UserActionLog(String actorName,String actionDescr,Short actionType,String actionResult){
        this.actorName=actorName;
        this.actionDescr=actionDescr;
        this.actionType=actionType;
        this.actionResult=actionResult;
        this.actionAt=new Date();
    }

}
